home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / demos / GL / snurb / draw.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  5.0 KB  |  265 lines

  1. /*
  2.  * Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. #include <gl.h>
  18. #include <math.h>
  19. #include <stdio.h>
  20. #include "defines.h"
  21. #include "device.h"
  22. #include "nurb.h"
  23. #include "snurb.h"
  24. #include "draw.h"
  25.  
  26. /* viewing */
  27. extern Matrix view_matrix;
  28.  
  29. /* motion */
  30. extern Boolean moving_control, moving_object, zipping;
  31. extern Coord motion_origin[3];
  32.  
  33. extern struct node_struct *root;
  34. extern struct node_struct *selected_patch;
  35. extern int move_s, move_t;
  36. extern int dest_s, dest_t;
  37. extern struct node_struct *zip_dest;
  38.  
  39. extern float pixel_tolerance;
  40. extern long snurb_window;
  41.  
  42. void draw_display(void)
  43. {
  44.     clear_window();
  45.     setnurbsproperty(N_PIXEL_TOLERANCE, pixel_tolerance);
  46.  
  47.     set_view(MVIEWING);
  48.     multmatrix(view_matrix);
  49.  
  50. /*    depthcue(TRUE);
  51.     lRGBrange(50,0,0,255,0,0,0,0x7fffff);
  52.     draw_cube(); */
  53.  
  54.     draw_children(root->child,FALSE);
  55.  
  56. #ifdef spaceball
  57.     sbPrmpt();
  58. #endif
  59.  
  60.     swapbuffers();
  61. }
  62.  
  63.  
  64. /* 
  65.  * Draws all the children of the parent node. If the parent is selected, then
  66.  * all of its children are also selected, and their control points and hulls 
  67.  * are drawn.
  68.  */
  69. void draw_children(struct node_struct *child, Boolean parent_selected)
  70. {
  71.     Boolean child_selected;
  72.  
  73.     if (child != NULL)
  74.     {
  75.         child_selected = (parent_selected || child->selected);
  76.     
  77.         if (child->node_type == PATCH)
  78.         {
  79.             if(child_selected)
  80.             {
  81.                 depthcue(TRUE);
  82.                 
  83.                 /* note the stupidity check for when window system misses mouse
  84.                             up events */
  85.                 if ((moving_control || moving_object) && (child == selected_patch))
  86.                 {
  87.                     draw_control_points(child->patch->control, move_s, move_t);
  88.                     
  89.                     draw_drop_lines(child->patch->control[move_s][move_t]);
  90.                 }
  91.                 else if ( zipping && (child == zip_dest))
  92.                     draw_control_points(child->patch->control, dest_s, dest_t);
  93.                 else
  94.                     draw_control_points(child->patch->control, NONE, NONE);
  95.                 
  96.                 draw_hulls(child->patch->control);
  97.             }
  98.             else if ( zipping && (child == zip_dest))
  99.             {
  100.                 depthcue(TRUE);
  101.                 draw_control_points(child->patch->control, dest_s, dest_t);
  102.                 draw_hulls(child->patch->control);
  103.             }
  104.  
  105.  
  106.             depthcue(FALSE);
  107.             lmbind(MATERIAL, 1);
  108.             draw_patch(child->patch->control);
  109.         }
  110.  
  111.         draw_children(child->child, child_selected);
  112.         draw_children(child->sibling, parent_selected);
  113.     }
  114. }
  115.  
  116.  
  117.  
  118. /*
  119.  * Clears the window and reinitialized the control point markers to
  120.  * none.
  121.  */
  122. void clear_window(void)
  123. {
  124.     cpack(0);
  125.     clear();
  126.     zclear();
  127. }
  128.  
  129.  
  130. void draw_control_points(Mesh control, int select_s, int select_t)
  131. {
  132.     int s,t;
  133.     int counter = 0;
  134.  
  135.     for(s = 0; s< NUMPOINTS; s++)
  136.         for(t = 0; t < NUMPOINTS; t++)
  137.         {
  138.             if ((s == select_s) && (t == select_t))
  139.                 lRGBrange(50,50,50,255,255,255,0,0x7fffff);
  140.             else
  141.                 lRGBrange(0,50,0,0,255,0,0,0x7fffff);
  142.             
  143.             pushmatrix();
  144.             translate(control[s][t][0],
  145.                       control[s][t][1],
  146.                       control[s][t][2]);
  147.             scale(.02, .02, .02);
  148.  
  149.             draw_cube();
  150.             popmatrix();
  151.         }
  152. }
  153.  
  154.  
  155. void draw_hulls(Mesh control)
  156. {
  157.     int s, t;
  158.     
  159.     lRGBrange(0,50,0,0,255,0,0,0x7fffff);
  160.     
  161.     for(s = 0; s< NUMPOINTS; s++)
  162.         for(t = 0; t < NUMPOINTS-1; t++)
  163.         {
  164.             bgnline();
  165.             v3f(control[s][t]);
  166.             v3f(control[s][t+1]);
  167.             endline();
  168.             
  169.             bgnline();
  170.             v3f(control[t][s]);
  171.             v3f(control[t+1][s]);
  172.             endline();
  173.         }        
  174. }
  175.  
  176.  
  177.  
  178. void draw_drop_lines(Coord c[3])
  179. {
  180.     Coord a[3],b[3];
  181.     int i;
  182.     extern Coord spaced_limit[3][2];
  183.  
  184.     lRGBrange(50,50,50,255,255,255,0,0x7fffff); 
  185.  
  186.     for (i=0; i<3; i++)
  187.     {
  188.         a[0] = b[0] = c[0];
  189.         a[1] = b[1] = c[1];
  190.         a[2] = b[2] = c[2];
  191.  
  192.         a[i] = spaced_limit[i][0];
  193.         b[i] = spaced_limit[i][1];
  194.  
  195.         bgnline();
  196.         v3f(a);
  197.         v3f(b);
  198.         endline();
  199.     }
  200.     
  201.  
  202. }
  203.  
  204.  
  205. /* The vertices of a cube centered about the origin with width 2 */
  206. Coord cube_vertex[8][3] =
  207.     {
  208.         {-1.0, -1.0, -1.0}, 
  209.         {-1.0, -1.0,  1.0}, 
  210.         {-1.0,  1.0,  1.0}, 
  211.         {-1.0,  1.0, -1.0}, 
  212.         { 1.0, -1.0, -1.0}, 
  213.         { 1.0, -1.0,  1.0}, 
  214.         { 1.0,  1.0,  1.0}, 
  215.         { 1.0,  1.0, -1.0}
  216.     };
  217.  
  218.  
  219. /*
  220.  * Draws the cube with vertices defined above.
  221.  */
  222. void draw_cube(void)
  223. {
  224.     bgnclosedline();
  225.     v3f(cube_vertex[0]);    
  226.     v3f(cube_vertex[1]);    
  227.     v3f(cube_vertex[2]);    
  228.     v3f(cube_vertex[3]);    
  229.     endclosedline();
  230.  
  231.     bgnclosedline();
  232.     v3f(cube_vertex[4]);    
  233.     v3f(cube_vertex[5]);    
  234.     v3f(cube_vertex[6]);    
  235.     v3f(cube_vertex[7]);
  236.     endclosedline();
  237.  
  238.     bgnline();
  239.     v3f(cube_vertex[0]);    
  240.     v3f(cube_vertex[4]);
  241.     endline();
  242.     
  243.     bgnline();
  244.     v3f(cube_vertex[1]);    
  245.     v3f(cube_vertex[5]);
  246.     endline();
  247.     
  248.     bgnline();
  249.     v3f(cube_vertex[2]);    
  250.     v3f(cube_vertex[6]);
  251.     endline();
  252.     
  253.     bgnline();
  254.     v3f(cube_vertex[3]);    
  255.     v3f(cube_vertex[7]);
  256.     endline();
  257. }
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.